package neusoft.edu.cn.guanshangshiguang.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import neusoft.edu.cn.guanshangshiguang.Listener.OnItemClickListener;
import neusoft.edu.cn.guanshangshiguang.R;
import neusoft.edu.cn.guanshangshiguang.bean.BookTypeBean;
import neusoft.edu.cn.guanshangshiguang.item.ReadItemViewHolder;

public class BookTypeListAdapter extends RecyclerView.Adapter<ReadItemViewHolder> {
    private List<BookTypeBean> bookTypeBeanDateList;
    private OnItemClickListener myOnItemClickListener;

    public void setOnItemClickListener(OnItemClickListener listener){
        myOnItemClickListener=listener;
    }

    public void setDate(List<BookTypeBean> dateItemList){
        this.bookTypeBeanDateList =dateItemList;
        notifyDataSetChanged();//通知数据集发生变化
    }

    @NonNull
    @Override
    public ReadItemViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        LayoutInflater layoutInflater = LayoutInflater.from(viewGroup.getContext());
        View itemView = layoutInflater.inflate(R.layout.item_layout,viewGroup,false);
        ReadItemViewHolder viewHolder = new ReadItemViewHolder(itemView);
        return viewHolder;

    }

    @Override
    public void onBindViewHolder(@NonNull final ReadItemViewHolder itemViewHolder, final int i) {
        final BookTypeBean bookResultList = bookTypeBeanDateList.get(i);

        itemViewHolder.textView2.setText(bookResultList.getTname());

        if(myOnItemClickListener!=null){
            itemViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    myOnItemClickListener.onItemClick(view,i);
                }
            });
        }

    }

    @Override
    public int getItemCount() {
        if(bookTypeBeanDateList !=null)
            return bookTypeBeanDateList.size();
        else
            return 0;
//        return shopDateList.size();//返回列表显示的数据个数
    }
}
